#include <gameuicontroller.h>
#include <gameuievent.h>
#include <macro.h>
#include <tui.h>
#include <cocos2d.h>
USING_NS_CC;

GameUIController* GameUIController::s_instance = NULL;
GameUIController* GameUIController::I()
{
	if( NULL == s_instance ){
		s_instance = new GameUIController();
		if (s_instance && s_instance->init()){   
			s_instance->autorelease();
		}else{   
			CC_SAFE_DELETE(s_instance);
			return NULL;
		}   
	}
	return s_instance;
}

GameUIController::GameUIController()
{
	/** register event callback, tui_event_cb_table defined in gameuievent.h,
	   	gameuievent.h is generated by flash cs TGameUITool extension.
	 */
	int ncb = sizeof(tui_event_cb_table)/sizeof(tui_event_cb_table[0]);
	TuiEventCallBackTable* ecb = NULL;
	for( int i=0; i<ncb; ++i ){
		ecb = tui_event_cb_table+i;
		registerEventCallBack( ecb->event, ecb->callback );
		tLogDebug( "register event: %s", ecb->event );
	}
}

GameUIController::~GameUIController()
{
}

void GameUIController::on_event_panel_start_click_btn_start( void* o, TEvent* e ){
	GameUIController::I()->closeAll();
	GameUIController::I()->showTui( s_t_panel_game );
}

void GameUIController::on_event_panel_game_click_btn_back( void* o, TEvent* e ){
	GameUIController::I()->closeAll();
	GameUIController::I()->showTui( s_t_panel_start );
}
